package com.qmx.qmxapp.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * @author chengxiangtong
 * @date 2018/12/10
 * version : 1.0
 * class describe：*
 */
public class CustomScrollViewPager extends ViewPager {
    //是否可以左右滑动？true 可以，像Android原生ViewPager一样。
    // false 禁止ViewPager左右滑动。
    private boolean mNoScoll = false;

    public CustomScrollViewPager(@NonNull Context context) {
        super(context);
    }

    public CustomScrollViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setScrollable(boolean mNoScoll) {
        this.mNoScoll = mNoScoll;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

        if (mNoScoll) {
            return false;
        } else {
            return super.onTouchEvent(ev);
        }


    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (mNoScoll) {
            return false;
        } else {
            return super.onInterceptTouchEvent(ev);
        }
    }
}
